﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.Entity;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;

namespace FrameWork.web.Code
{
    public class sys_UserCs
    {
        public sys_UserCs()
        {
            Microsoft.ApplicationBlocks.Data.SqlHelper.connectionString = ConfigurationManager.AppSettings["MsSql"].ToString();
        }
        /// <summary>
        /// 根据报修人工号查找人员信息
        /// </summary>
        /// <param name="_its_DocNoTable"></param>
        /// <returns></returns>

        public DataTable User_SelectInfoByU_UserNO(sys_User _sys_User)
        {
            SqlParameter[] sp = new SqlParameter[1]{
				new SqlParameter("@U_UserNO",SqlDbType.VarChar,20),
			
			};
            //

            sp[0].Value = _sys_User.U_UserNO;
            sp[0].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_User_SelectInfoByU_UserNO", sp);
                DataTable dt = ds.Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据姓名、部门以及工号查询
        /// </summary>
        /// <param name="_sys_User"></param>
        /// <returns></returns>
        public DataTable User_SelectInfoByU_CNameAndU_GroupIDAndU_UserNO(sys_User _sys_User)
        {
            SqlParameter[] sp = new SqlParameter[3]{
				new SqlParameter("@U_CName",SqlDbType.NVarChar,40),
				new SqlParameter("@U_GroupID",SqlDbType.NVarChar,20),
				new SqlParameter("@U_UserNO",SqlDbType.VarChar,20),
			
			};
            //
            if (_sys_User.U_CName != "")
            {
                sp[0].Value = _sys_User.U_CName.Replace("'","''");
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //
            if (_sys_User.U_GroupID != int.MinValue)
            {
                sp[1].Value = _sys_User.U_GroupID;
            }
            else
            {
                sp[1].Value = DBNull.Value;
            }

            sp[1].Direction = ParameterDirection.Input;


            //
            if (_sys_User.U_UserNO != "")
            {
                sp[2].Value = _sys_User.U_UserNO.Replace("'","''");
            }
            else
            {
                sp[2].Value = DBNull.Value;
            }

            sp[2].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_User_SelectInfoByU_CNameAndU_GroupIDAndU_UserNO", sp);
                DataTable dt = ds.Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="_sys_User"></param>

        public string UserChangePWD(sys_User _oldsys_User, sys_User _newsys_User)
        {
            SqlParameter[] sp = new SqlParameter[4]{
				new SqlParameter("@UserID",SqlDbType.Int),
				new SqlParameter("@Old_U_Password",SqlDbType.VarChar,32),
				new SqlParameter("@New_U_Password",SqlDbType.VarChar,32),
				new SqlParameter("@Meg",SqlDbType.NVarChar,100),
			
			};
            //

            sp[0].Value = _oldsys_User.UserID;
            sp[0].Direction = ParameterDirection.Input;


            //

            sp[1].Value = _oldsys_User.U_Password;
            sp[1].Direction = ParameterDirection.Input;


            //

            sp[2].Value = _newsys_User.U_Password;
            sp[2].Direction = ParameterDirection.Input;


            //
            sp[3].Direction = ParameterDirection.Output;

            try
            {
                SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_UserChangePWD", sp);
                return sp[3].Value.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
